package com.eeb.dropwizardmongo.example.api;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotBlank;
import org.mongojack.MongoCollection;
import org.mongojack.ObjectId;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
@MongoCollection(name = "tracks")
public class Track {

    @JsonProperty("_id")
    private String _id;

    @NotBlank
    @JsonProperty("name")
    private String name;

    @NotBlank
    @JsonProperty("organization")
    private String organization;

    @JsonProperty("assignments")
    private List<String> assignments = new LinkedList<>();

    @JsonProperty("badges")
    private List<String> badges = new ArrayList<>();

    public Track() {
    }

    public Track(@ObjectId String _id, String name, String organization) {
        this._id = _id;
        this.name = name;
        this.organization = organization;
    }

    @ObjectId
    public String get_id() {
        return _id;
    }

    public void set_id(String _id) {
        this._id = _id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOrganization() {
        return organization;
    }

    public void setOrganization(String organization) {
        this.organization = organization;
    }

    public List<String> getAssignments() {
        return assignments;
    }

    public void setAssignments(List<String> assignments) {
        this.assignments = assignments;
    }

    public void addAssignment(String user) {
        if (!assignments.contains(user)) assignments.add(user);
    }

    public boolean removeAssignment(String user) {
        return assignments.remove(user);
    }

    public boolean hasAssignment(String user) {
        return assignments.contains(user);
    }

    public List<String> getBadges() {
        return badges;
    }

    public void setBadges(List<String> badges) {
        this.badges = badges;
    }

    public void addBadge(String user) {
        if (!badges.contains(user)) badges.add(user);
    }

    public boolean removeBadge(String user) {
        return badges.remove(user);
    }

    public boolean hasBadge(String user) {
        return badges.contains(user);
    }

}